/**
 * 
 */
package org.youisoft.summer.evaluator.unit;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.youisoft.summer.evaluator.InvokeException;
import org.youisoft.summer.evaluator.UnitEnum;
import org.youisoft.summer.evaluator.context.CalContext;
import org.youisoft.summer.evaluator.operator.Operator;
import org.youisoft.summer.evaluator.operator.base.ClosureOperator;


/**
 * @author zijiang.jl
 *
 */
public abstract class AbstractBrace<R,P> extends AbstractUnit<R,P> implements Brace<R,P>{

	protected static final Log logger=LogFactory.getLog(Brace.class);

	@Override
	public void init() {
		super.init();
		if(this.getfName()==null||"".equals(this.getfName())) this.setfName(Brace.class.getName());
	}

	@Override
	public <C> void accept(CalContext<C, R, P> context, UnitVisitor<R, P> visitor)
			throws InvokeException {
		logger.debug("accept visitor......");
		this.setProperty(visitor.getProperty());
		this.setResource(visitor.getResource());
		logger.debug("begin visit......"+this.getClass().getName());
		visitor.visit(context,this);
		logger.debug("end visit......");
		
	}

	@Override
	public <C> Operator<?> doCalculate(CalContext<C,R,P> context,Operator<?> operator)
			throws InvokeException {
		return this.callFunctionIfNessary(context, new ClosureOperator(this.getContent()).setName(getfName()).setRegistry(this.getRegistry()));
	}

	@Override
	public UnitEnum getUnitType() {
		return UnitEnum.brace;
	}
	
	
}
